package com.wpzf.zxhc.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.monitorjbl.xlsx.StreamingReader;
import com.wpzf.common.core.utils.StringUtils;
import com.wpzf.common.core.utils.sign.Base64;
import com.wpzf.zxhc.utils.MultipleFileUnZip;
import com.wpzf.zxhc.domain.*;
import com.wpzf.zxhc.mapper.*;
import com.wpzf.zxhc.service.CommonSjService;
import com.wpzf.zxhc.service.ProvAuditingService;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.gdal.gdal.gdal;
import org.gdal.ogr.*;
import org.gdal.osr.SpatialReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.ui.ModelMap;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@SuppressWarnings("unchecked")
public class ProvAuditingServiceImpl implements ProvAuditingService {
    @Autowired
    ProvAuditingMapper provAuditingMapper;
    @Autowired
    CommonSjMapper commonSjMapper;

    @Autowired
    XzqdmMapper xzqdmMapper;


    @Autowired
    WpCjTbhcjgSjMapper wpCjTbhcjgSjMapper;
    @Autowired
    YtbTbInfoMapper ytbTbInfoMapper;
    @Autowired
    XjtbTbBaseMapper xjtbTbBaseMapper;
    @Autowired
    DkShCityMapper dkShCityMapper;

    @Value("${tempath}")
    public String tempath;


    MultipleFileUnZip multipleFileUnZip = new MultipleFileUnZip();

    @Override
    public List<ProvAuditingInfo> getAuditingInfo(Map<String, Object> map) {
        return provAuditingMapper.getAuditingInfo(map);
    }

    @Override
    public Integer getAuditingInfoCount(Map<String, Object> map) {
        return provAuditingMapper.getAuditingInfoCount(map);
    }

    @Override
    public List<Map> getPch(Map<String, Object> map) {
        return provAuditingMapper.getPch(map);
    }

    @Override
    public List<Map> getDkDetailByXzq(Map<String, Object> map) {
        return provAuditingMapper.getDkDetailByXzq(map);
    }

    @Override
    public List<Map> getDkDetailAllByXzq(Map<String, Object> map) {
        return provAuditingMapper.getDkDetailAllByXzq(map);
    }

    @Override
    public List<Map> getDkDetailAllByIndex(Map<String, Object> map) {
        return provAuditingMapper.getDkDetailAllByIndex(map);
    }

    @Override
    public Integer getDkDetailByXzqCount(Map<String, Object> map) {
        return provAuditingMapper.getDkDetailByXzqCount(map);
    }

    @Override
    public WpCjDkxxbxj2023DTO getDkInfoByDkbh(Map<String, Object> map) {
        WpCjDkxxbxj2023DTO dkxxbxj2023DTO = provAuditingMapper.getDkInfoByDkbh(map);
        if ("合法".equals(dkxxbxj2023DTO.getPdlx())) {
            //dkxxbxj2023DTO.setHfpwList(ytbTbInfoMapper.queryWpCjDkxxbxjHfpw2023ByDkbh(dkxxbxj2023DTO));
        }
        return dkxxbxj2023DTO;
    }

    @Override
    public List<WpCjDkxxbxj2023DTO> getRelationDkInfoByJcbh(Map<String, Object> map) {
        List<WpCjDkxxbxj2023DTO> dkxxbxj2023DTOList = provAuditingMapper.getRelationDkInfoByJcbh(map);
        for (WpCjDkxxbxj2023DTO wpCjDkxxbxj2023DTO : dkxxbxj2023DTOList) {
            if ("合法".equals(wpCjDkxxbxj2023DTO.getPdlx())) {
                //wpCjDkxxbxj2023DTO.setHfpwList(ytbTbInfoMapper.queryWpCjDkxxbxjHfpw2023ByDkbh(wpCjDkxxbxj2023DTO));
            }
        }
        return dkxxbxj2023DTOList;
    }

    @Override
    public List<WpCjTbxxbxj2023DTO> getTbInfoByJcbh(Map<String, Object> map) {
        return provAuditingMapper.getTbInfoByJcbh(map);
    }

    @Override
    public WpCjTbhcjgSj2023 getTbHcJgInfo(Map<String, Object> map) {
        WpCjTbhcjgSj2023 wpCjTbhcjgSj2023 = wpCjTbhcjgSjMapper.getTbhcjgSjInfo(map);
        if (wpCjTbhcjgSj2023 != null) {
            List<WpCjTbhcjgSjHftgzmwj2023> xjHftgzmwj2023List = wpCjTbhcjgSjMapper.getTbhcjgSjHftgzmwjInfo(map);
            wpCjTbhcjgSj2023.setSjHftgzmwj2023List(xjHftgzmwj2023List);
            List<WpCjTbhcjgSjQtpzwh2023> xjQtpzwh2023List = wpCjTbhcjgSjMapper.getTbhcjgSjQtpzwhInfo(map);
            wpCjTbhcjgSj2023.setSjQtpzwh2023List(xjQtpzwh2023List);
            List<WpCjTbhcjgSjQtsftgxxydss2023> xjQtsftgxxydss2023List = wpCjTbhcjgSjMapper.getTbhcjgSjQtsftgxxydssInfo(map);
            wpCjTbhcjgSj2023.setSjQtsftgxxydss2023List(xjQtsftgxxydss2023List);
            List<WpCjTbhcjgSjQtsfzygd2023> xjQtsfzygd2023List = wpCjTbhcjgSjMapper.getTbhcjgSjQtsfzygdInfo(map);
            wpCjTbhcjgSj2023.setSjQtsfzygd2023List(xjQtsfzygd2023List);
            List<WpCjTbhcjgSjWfpzwh2023> xjWfpzwh2023List = wpCjTbhcjgSjMapper.getTbhcjgSjWfpzwhInfo(map);
            wpCjTbhcjgSj2023.setSjWfpzwh2023List(xjWfpzwh2023List);
            List<WpCjTbhcjgSjWftgzmwj2023> xjWftgzmwj2023List = wpCjTbhcjgSjMapper.getTbhcjgSjWftgzmwjInfo(map);
            wpCjTbhcjgSj2023.setSjWftgzmwj2023List(xjWftgzmwj2023List);
        }
        return wpCjTbhcjgSj2023;
    }

    @Override
    public List<Map> getDkHcZzJgInfo(Map<String, Object> map) {
        return provAuditingMapper.getDkHcZzJgInfo(map);
    }

    @Override
    public List<Map> getDkHcZzJgPch(Map<String, Object> map) {
        return provAuditingMapper.getDkHcZzJgPch(map);
    }

    @Override
    public Integer getDkHcZzJgInfoCount(Map<String, Object> map) {
        return provAuditingMapper.getDkHcZzJgInfoCount(map);
    }

    @Override
    public List<Map> getDkHcJgByXzq(Map<String, Object> map) {
        return provAuditingMapper.getDkHcJgByXzq(map);
    }

    @Override
    public Integer getDkHcJgByXzqCount(Map<String, Object> map) {
        return provAuditingMapper.getDkHcJgByXzqCount(map);
    }

    @Override
    public List<Map> getBtgDkJgAll(Map<String, Object> map) {
        List<Map> list = provAuditingMapper.getBtgDkJgAll(map);
        List<Map> listNew = new ArrayList<>();
        List<String> listStr = new ArrayList<>();
        for (Map m : list) {
            if (!listStr.contains(m.get("dkbh").toString())) {
                listNew.add(m);
                listStr.add(m.get("dkbh").toString());
            }
        }
        return listNew;
    }

    @Override
    public Integer getBtgDkJgAllCount(Map<String, Object> map) {
        return provAuditingMapper.getBtgDkJgAllCount(map);
    }

    @Override
    public List<Map> getBtgDkXzqh(Map<String, Object> map) {
        return provAuditingMapper.getBtgDkXzqh(map);
    }

    @Override
    public List<Map> getBtgDkPch(Map<String, Object> map) {
        return provAuditingMapper.getBtgDkPch(map);
    }

    @Override
    public Integer dkshSjSubmit(Map<String, Object> map) {
        Integer n = 0;
        List<String> listDkbh = Arrays.asList(map.get("dkbh").toString().split(",").clone());
        List<String> listxzqdm = Arrays.asList(map.get("xzqdm").toString().split(",").clone());
        String xzqdm = map.get("xzqdm").toString();
        for (int i = 0; i < listDkbh.size(); i++) {
            String dkbh = listDkbh.get(i);
            if (listxzqdm.size() > 1) {
                map.replace("xzqdm", listxzqdm.get(i).toString()); //行政区代码
            }
            {
                map.replace("dkbh", dkbh); //地块编号
                map.put("thsj", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime())); //更新状态即可 状态更新为  7
                Integer nUpCount = provAuditingMapper.updateSjSftjByDkbh(map);
                Integer nUpCountw = provAuditingMapper.updateSjSftjByDkbhshj(map);

                //退回插入流转表
                map.put("czsj", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
                map.put("result", "不通过");
                map.put("sm", map.get("thyy").toString());
                Integer count = xjtbTbBaseMapper.saveDkxxbxjlz(map);
            }
            n++;
        }

        return n;
    }

    //按照行政区划提交
    @Override
    public Integer dkshDgSubmit(Map<String, Object> map) {
        Integer n = 0;
        List<String> listxzqh = Arrays.asList(map.get("xzqdm").toString().split(",").clone());
        for (String xzqdm : listxzqh) {
            map.replace("xzqdm", xzqdm); //更新状态即可 状态更新为  8
            Integer nUpCount = provAuditingMapper.updateSjSftjByxzqdm(map); //更新该图斑完成操作
            //是否提交为是
            Integer count = provAuditingMapper.updatejgByxzqdm(map); //更新该图斑完成操作
            n++;
        }
        return n;
    }

    @Override
    public List<Map> getxianbyPch(Map<String, Object> parm) {
        return provAuditingMapper.getxianbyPch(parm);
    }

    private Class getClassByStringName(String name) {
        if ("".equals(name) || Objects.isNull(name)) return String.class;
        switch (name) {
            case "id": {
                return Integer.class;
            }
            case "nf": {
                return String.class;
            }
            case "tbxfsj": {
                return String.class;
            }
            case "pcxx": {
                return String.class;
            }
            case "smc": {
                return String.class;
            }
            case "uploadid": {
                return String.class;
            }
            case "smc1": {
                return String.class;
            }
            case "qxmc": {
                return String.class;
            }
            case "wkt": {
                return String.class;
            }
            case "xzqdm": {
                return String.class;
            }
            case "jcbh": {
                return String.class;
            }
            case "tblx": {
                return String.class;
            }
            case "qsx": {
                return String.class;
            }
            case "hsx": {
                return String.class;
            }
            case "tbzxdjd": {
                return String.class;
            }
            case "dqjh": {
                return String.class;
            }
            case "bz": {
                return String.class;
            }
            case "jctbxzgdmj": {
                return Double.class;
            }
            case "jctbxznydzmj": {
                return Double.class;
            }
            case "wqtbbh": {
                return String.class;
            }
            case "tbzxdwd": {
                return String.class;
            }
            case "jcmj": {
                return Double.class;
            }
            case "sfcxbhtb": {
                return String.class;
            }
            case "dlrdjsydmj": {
                return Double.class;
            }
            case "dlrdwlydmj": {
                return Double.class;
            }
            case "zjbntmj": {
                return Double.class;
            }
            case "mjzbzddsdxjxzqdm": {
                return String.class;
            }
            case "mjzbzddsdxjxzqmc": {
                return String.class;
            }
            case "mjzbzddxzjxzqdm": {
                return String.class;
            }
            case "mjzbzddxzjxzqmc": {
                return String.class;
            }
            case "mjzbzddcjxzqdm": {
                return String.class;
            }
            case "mjzbzddcjxzqmc": {
                return String.class;
            }
            case "nzyjsydxmtbzj": {
                return String.class;
            }
            case "tdzzysxm": {
                return String.class;
            }
            case "zjggxmcjq": {
                return String.class;
            }
            case "zjggxmjxq": {
                return String.class;
            }
            case "gkfqdfkxm": {
                return String.class;
            }
            case "wlydkfxm": {
                return String.class;
            }
            case "gdxx": {
                return String.class;
            }
            case "ysxmxx": {
                return String.class;
            }
            case "ssnydxx": {
                return String.class;
            }
            case "xxydxx": {
                return String.class;
            }
            case "kqxx": {
                return String.class;
            }
            case "qtkqxx": {
                return String.class;
            }
            case "sklx": {
                return String.class;
            }
            case "tskqmj": {
                return String.class;
            }
            case "yjmj": {
                return String.class;
            }
            case "zrbhqxx": {
                return String.class;
            }
            case "ysxwpdlrdgdmj": {
                return Double.class;
            }
            case "ysxwpdlrdnydmj": {
                return Double.class;
            }
            case "ysxwpdlrdjsydmj": {
                return Double.class;
            }
            case "ysxwpdlrdwlydmj": {
                return Double.class;
            }
            case "ysxwpdlrdjbntmj": {
                return Double.class;
            }
            case "wsxwpdlrdgdmj": {
                return Double.class;
            }
            case "wsxwpdlrdnydmj": {
                return Double.class;
            }
            case "wsxwpdlrdjsydmj": {
                return Double.class;
            }
            case "wsxwpdlrdwlydmj": {
                return Double.class;
            }
            case "wsxwpdlrdstmj": {
                return Double.class;
            }
            case "wsxwpdlrdjbntmj": {
                return Double.class;
            }
            case "sffgdk": {
                return String.class;
            }
            case "skbj": {
                return String.class;
            }
            case "tbfl": {
                return String.class;
            }
            case "xgsj": {
                return String.class;
            }
            case "stbhhxmj": {
                return Double.class;
            }
            case "tbbsm": {
                return String.class;
            }
            case "pch": {
                return String.class;
            }
            case "nd": {
                return String.class;
            }
            case "opTime": {
                return String.class;
            }
            case "receivingCode": {
                return String.class;
            }
            case "iscl": {
                return String.class;
            }
            case "Real": {
                return Double.class;
            }
            default:
                return String.class;
        }
    }

    public static boolean deleteDirectory(File directoryToBeDeleted) {
        File[] allContents = directoryToBeDeleted.listFiles();
        if (allContents != null) {
            for (File file : allContents) {
                deleteDirectory(file);
            }
        }
        return directoryToBeDeleted.delete();
    }

    @Override
    public String importDataByshp(String sFilePath, String uploadid) {
//         // 为了支持中文路径，请添加下面这句代码
        gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
//         // 为了使属性表字段支持中文，请添加下面这句
        gdal.SetConfigOption("SHAPE_ENCODING", "UTF-8");

        // 设置GDAL的字符编码
        System.setProperty("JAVA_OPTS", "-Dfile.encoding=UTF-8");
// 或者使用GBK，取决于你的矢量数据实际编码
        System.setProperty("JAVA_OPTS", "-Dfile.encoding=GBK");


        try {
            //步骤1：解压获取shp
            File file = new File(sFilePath);
            String name = file.getName();
            String dirName = file.getName();
            if (name.lastIndexOf(".") > 0) {
                dirName = name.substring(0, name.lastIndexOf("."));
            }
            //输出路径
            String outPath = file.getParent() + "\\" + dirName;
            File folder = new File(outPath);
            // 检查文件夹是否存在
            if (folder.exists() && folder.isDirectory()) {
                // 文件夹存在，删除文件夹
                deleteDirectory(folder);
            }
            Random random = new Random();
            //解压
            Boolean flag = multipleFileUnZip.fileUnZip(sFilePath, outPath);
            if (!flag) {
                return "解压失败";
            }
            File[] files = new File(outPath).listFiles();
            String shpfilePath = "";
            if (files.length > 0) {
                for (int i = 0; i < files.length; i++) {
                    File file2 = files[i];
                    if (file2.getName().endsWith("shp")) {
                        shpfilePath = file2.getPath();
                    }
                }
                System.out.println("shp" + shpfilePath);
            }
            if (shpfilePath.isEmpty()) {
                return "所上传数据无矢量文件";
            } else {
                List<WpCjTbxxbxj2023DTO> models = new ArrayList<WpCjTbxxbxj2023DTO>();


                Class cls = Class.forName("com.wpzf.zxhc.domain.WpCjTbxxbxj2023DTO");

                Field[] fields = cls.getDeclaredFields();
                //步骤2：解析shp文件 坐标系
                DataSource dataSource = ogr.Open(shpfilePath, 0);
                Layer layer = dataSource.GetLayer(0); //获取图层
                SpatialReference spatialReference = layer.GetSpatialRef();
                //System.out.println("空间参考坐标系：" + spatialReference.GetAttrValue("AUTHORITY", 0)
                // + spatialReference.GetAttrValue("AUTHORITY", 1));
                //步骤2：解析shp文件 空间范围
                double[] layerExtent = layer.GetExtent();
                System.out.println("图层范围：minx:" + layerExtent[0] + ",maxx:" + layerExtent[1] + ",miny:" + layerExtent[2] + ",maxy:" + layerExtent[3]);
                //步骤2：解析shp文件 属性字段
                //获取图层的字段信息
                List<String> fieldNames = new ArrayList<String>();
                List<String> zhNames = new ArrayList<String>();
                FeatureDefn featureDefn = layer.GetLayerDefn();
                int fieldCount = featureDefn.GetFieldCount();
                for (int i = 0; i < fieldCount; i++) {
                    FieldDefn fieldDefn = featureDefn.GetFieldDefn(i);
                    // 得到属性字段类型
                    int fieldType = fieldDefn.GetFieldType();
                    String fieldTypeName = fieldDefn.GetFieldTypeName(fieldType);
                    // 得到属性字段名称
                    String fieldName = fieldDefn.GetName().toLowerCase();
                    fieldNames.add(fieldName);
                }
//                System.out.println("所有字段名：" + fieldNames);
                zhNames.add("jctbxzgdmj");
                zhNames.add("jctbxznydzmj");
                zhNames.add("dlrdjsydmj");
                zhNames.add("dlrdwlydmj");
                zhNames.add("zjbntmj");
                zhNames.add("mjzbzddxzjxzqdm");
                zhNames.add("mjzbzddxzjxzqmc");
                zhNames.add("mjzbzddsdxjxzqdm");
                zhNames.add("mjzbzddsdxjxzqmc");
                zhNames.add("mjzbzddcjxzqdm");
                zhNames.add("mjzbzddcjxzqmc");
                zhNames.add("ysxwpdlrdgdmj");
                zhNames.add("ysxwpdlrdnydmj");
                zhNames.add("ysxwpdlrdjsydmj");
                zhNames.add("ysxwpdlrdwlydmj");
                zhNames.add("ysxwpdlrdjbntmj");
                zhNames.add("wsxwpdlrdgdmj");
                zhNames.add("wsxwpdlrdnydmj");
                zhNames.add("wsxwpdlrdjsydmj");
                zhNames.add("wsxwpdlrdwlydmj");
                zhNames.add("wsxwpdlrdstmj");
                zhNames.add("wsxwpdlrdjbntmj");
                zhNames.add("nzyjsydxmtbzj");

                zhNames.add("stbhhxmj");
                zhNames.add("ssnydxx");
                zhNames.add("zjbntmj");
                //获取实体类的字段信息
                LinkedHashMap<String, Class> classMap = new LinkedHashMap<>();
                Field[] fieldsst = cls.getDeclaredFields();
                for (Field field : fieldsst) {
                    String fieldName = field.getName();
                    classMap.put(fieldName, getClassByStringName(fieldName));
                }

                //步骤2：解析shp文件 属性字段值
                for (int i = 0; i < layer.GetFeatureCount(); i++) {
                    Feature feature = layer.GetFeature(i);
                    Object obj = cls.newInstance();
                    //解析范围
                    Geometry geometry = feature.GetGeometryRef();
                    String wkt = geometry.ExportToWkt() + ";" + geometry.Centroid().GetX() + ";" + geometry.Centroid().GetY();
                    //所有字段
                    for (Map.Entry<String, Class> entry : classMap.entrySet())  //按照实体类来
                    {
                        String fieldName = entry.getKey(); //实体类
//                        if(fieldName.equals("jcmj"))
//                        {
//                            System.out.println(fieldName);
//                        }
                        if (fieldName.equals("wkt")) {
                            Method method = cls.getDeclaredMethod("set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1), entry.getValue());
                            method.invoke(obj, wkt);
                        } else if (fieldNames.contains(fieldName) || zhNames.contains(fieldName)) {
                            Method method = cls.getDeclaredMethod("set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1), entry.getValue());
                            String shpName = fieldName;
                            if (fieldName == "jctbxzgdmj") {
                                shpName = "DLRDGDMJ";
                            } else if (fieldName == "ssnydxx") {
                                shpName = "SSNYDMJ";
                            } else if (fieldName == "zjbntmj") {
                                shpName = "JBNTMJ";
                            } else if (fieldName == "stbhhxmj") {
                                shpName = "STBHHXMJ";
                            } else if (fieldName == "jctbxznydzmj") {
                                shpName = "DLRDNYDMJ";
                            } else if (fieldName == "dlrdjsydmj") {
                                shpName = "DLRDJSYDMJ";
                            } else if (fieldName == "nzyjsydxmtbzj") {
                                shpName = "NZY";
                            } else if (fieldName == "dlrdwlydmj") {
                                shpName = "DLRDWLYDMJ";
                            } else if (fieldName == "zjbntmj") {
                                shpName = "JBNTMJ";
                            } else if (fieldName == "mjzbzddxzjxzqdm") {
                                shpName = "TB_XZJXZQD";
                            } else if (fieldName == "mjzbzddxzjxzqmc") {
                                shpName = "TB_XZJXZQM";
                            } else if (fieldName == "mjzbzddsdxjxzqdm") {
                                shpName = "XZQDM";
                            } else if (fieldName == "mjzbzddsdxjxzqmc") {
                                shpName = "XZQMC";
                            } else if (fieldName == "mjzbzddcjxzqdm") {
                                shpName = "TB_CJXZQDM";
                            } else if (fieldName == "mjzbzddcjxzqmc") {
                                shpName = "TB_CJXZQMC";
                            }
                            //
                            else if (fieldName == "ysxwpdlrdgdmj") {
                                shpName = "YSX_DLRDGD";
                            } else if (fieldName == "ysxwpdlrdnydmj") {
                                shpName = "YSX_DLRDNY";
                            } else if (fieldName == "ysxwpdlrdjsydmj") {
                                shpName = "YSX_DLRDJS";
                            } else if (fieldName == "ysxwpdlrdwlydmj") {
                                shpName = "YSX_DLRDWL";
                            } else if (fieldName == "ysxwpdlrdjbntmj") {
                                shpName = "YSX_DLRDJB";
                            } else if (fieldName == "wsxwpdlrdgdmj") {
                                shpName = "WSX_DLRDGD";
                            } else if (fieldName == "wsxwpdlrdnydmj") {
                                shpName = "WSX_DLRDNY";
                            } else if (fieldName == "wsxwpdlrdjsydmj") {
                                shpName = "WSX_DLRDJS";
                            }
                            //
                            else if (fieldName == "wsxwpdlrdwlydmj") {
                                shpName = "WSX_DLRDWL";
                            } else if (fieldName == "wsxwpdlrdstmj") {
                                shpName = "WSX_DLRDST";
                            } else if (fieldName == "wsxwpdlrdjbntmj") {
                                shpName = "WSX_DLRDJB";
                            }

                            try {
                                if (method != null && !fieldName.equals("id")) {
                                    String fvalue = feature.GetFieldAsString(shpName);
                                    method.invoke(obj, fvalue);
                                }

                            } catch (Exception ex) {
                                if (method != null && !fieldName.equals("id")) {
                                    Double fvalue = feature.GetFieldAsDouble(shpName);
                                    method.invoke(obj, fvalue);
                                }
                                continue;
                            }
                        } else {
                            continue;
                        }
                    }
                    //实体插入obj
                    Map<String, Object> parm = new HashMap<>();
                    parm.put("xzqdm", ((WpCjTbxxbxj2023DTO) obj).getXzqdm());
                    Map<String, String> res = xzqdmMapper.getall(parm);
                    if (res != null) {
                        ((WpCjTbxxbxj2023DTO) obj).setUploadid(uploadid);
                        ((WpCjTbxxbxj2023DTO) obj).setQxmc(res.get("xian"));
                        ((WpCjTbxxbxj2023DTO) obj).setSmc1(res.get("shi"));
                        ((WpCjTbxxbxj2023DTO) obj).setSmc(res.get("sheng"));
                    }
                    ((WpCjTbxxbxj2023DTO) obj).setUploadid(uploadid);
                    ((WpCjTbxxbxj2023DTO) obj).setPch("自主提取补充");
                    ((WpCjTbxxbxj2023DTO) obj).setPcxx("自主提取");
                    ((WpCjTbxxbxj2023DTO) obj).setId(random.nextInt());
                    ((WpCjTbxxbxj2023DTO) obj).setGjxfhzztq("自主提取");
                    //面积初始化
//                    ((WpCjTbxxbxj2023DTO) obj).setJctbxznydzmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setJctbxzgdmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setDlrdwlydmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setDlrdjsydmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setZjbntmj(0.00);
//
//                    ((WpCjTbxxbxj2023DTO) obj).setYsxwpdlrdgdmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setYsxwpdlrdjbntmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setYsxwpdlrdjsydmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setYsxwpdlrdnydmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setYsxwpdlrdwlydmj(0.00);
//
//
//                    ((WpCjTbxxbxj2023DTO) obj).setWsxwpdlrdgdmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setWsxwpdlrdjbntmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setWsxwpdlrdjsydmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setWsxwpdlrdnydmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setWsxwpdlrdwlydmj(0.00);
//                    ((WpCjTbxxbxj2023DTO) obj).setWsxwpdlrdstmj(0.00);

                    models.add((WpCjTbxxbxj2023DTO) obj);
                }
                boolean b = InsertBatch(models);
                if (b) {
                    System.out.println("导入图斑信息成功");
                    //导入地块信息 表
                    List<WpCjDkxxbxj2023DTO> dkmodels = new ArrayList<WpCjDkxxbxj2023DTO>();
                    WpCjDkxxbxj2023DTO dkmodel = new WpCjDkxxbxj2023DTO();
                    for (int i = 0; i < models.size(); i++) {
                        WpCjTbxxbxj2023DTO model = models.get(i);
                        dkmodel = new WpCjDkxxbxj2023DTO();
                        dkmodel.setXzqdm(model.getXzqdm());
                        dkmodel.setTbbh(model.getJcbh());
                        dkmodel.setDkbh(model.getJcbh());
                        dkmodel.setThdkmj(model.getJcmj());
                        dkmodel.setThdkgdmj(model.getJctbxzgdmj());
                        dkmodel.setThdkzjbntmj(model.getZjbntmj());
                        dkmodel.setThnydmj(model.getJctbxznydzmj());
                        dkmodel.setThdkstmj(model.getWsxwpdlrdstmj());

                        dkmodel.setTbdkmj(model.getJcmj());
                        dkmodel.setTbdkqzgdmj(model.getJctbxzgdmj());
                        dkmodel.setTbdkqzjbntmj(model.getZjbntmj());
                        dkmodel.setTbnydmj(model.getJctbxznydzmj());
                        dkmodel.setTbdkstmj(model.getWsxwpdlrdstmj());
                        dkmodel.setTbdkstbhhxmj(0.00);

                        dkmodel.setJcbh(model.getJcbh());
                        dkmodel.setXian(model.getQxmc());
                        dkmodel.setShi(model.getSmc1());
                        dkmodel.setWkt(model.getWkt().split(";")[0].toString());
                        dkmodel.setUid(UUID.randomUUID().toString().replace("-", ""));
                        dkmodel.setPch("自主提取补充");
                        dkmodel.setIsdel("0");
                        dkmodels.add(dkmodel);
                    }
                    b = InsertBatch1(dkmodels);
                    if (b) {
                        System.out.println("导入地块信息成功");
                        return "";
                    } else {
                        return "导入地块信息失败";
                    }

                } else {
                    return "导入图斑信息失败";
                }
            }
        } catch (Exception ex) {
            return ex.toString();
        }
    }


    @Override
    public List<Map> getBtgDkList(Map<String, Object> map) {
        return provAuditingMapper.getBtgDkList(map);
    }

    @Override
    public List<Map> getBtgDkJgAllByIndex(Map<String, Object> map) {
        return provAuditingMapper.getBtgDkJgAllByIndex(map);
    }

    @Override
    public WpCjDkxxbxj2023DTO getBtgDkInfoByDkbh(Map<String, Object> map) {
        return provAuditingMapper.getBtgDkInfoByDkbh(map);
    }

    @Override
    public List<WpCjDkxxbxj2023DTO> getBtgRelationDkInfoByJcbh(Map<String, Object> map) {
        List<WpCjDkxxbxj2023DTO> list = provAuditingMapper.getBtgRelationDkInfoByJcbh(map);
        List<WpCjDkxxbxj2023DTO> listDk = new ArrayList<>();
        List<String> lstStr = new ArrayList<>();
        for (WpCjDkxxbxj2023DTO dk : list) {
            if (!lstStr.contains(dk.getDkbh())) {
                listDk.add(dk);
                lstStr.add(dk.getDkbh());
            }
        }
        return listDk;
    }

    @Override
    public Integer btgDkshSjSubmit(Map<String, Object> map) {
        Integer n = 0;
        List<String> listDkbh = Arrays.asList(map.get("dkbh").toString().split(",").clone());
        for (String dkbh : listDkbh) {
            map.replace("dkbh", dkbh);
            Integer nDelCount = provAuditingMapper.clearBtgDkInfoByDkbh(map);
            Integer nInCount = provAuditingMapper.insertWtgDkByDkbhEx(map);
            if (nInCount == 0) {//二次验证通过
                /**
                 * 删除标记为0的地块
                 * 更新标记为1的地块
                 * */
                provAuditingMapper.delDkByDkbh(map);
                provAuditingMapper.updateDkByDkbh(map);
                Integer nUpCount = provAuditingMapper.updateSjSftjByDkbh(map);
            }
            n++;
        }
        return n;
    }

    @Override
    public List<Map> getProvExtractionData(Map<String, Object> map) {
        return provAuditingMapper.getProvExtractionData(map);
    }

    @Override
    public Integer getProvExtractionDataCount(Map<String, Object> map) {
        return provAuditingMapper.getProvExtractionDataCount(map);
    }


    @Override
    public String uploadFile(MultipartFile mFile) {
        String fileUrl = tempath + "\\" + mFile.getOriginalFilename();
        try {
            //使用此方法保存必须要绝对路径且文件夹必须已存在,否则报错
            File localFile = new File(fileUrl);
            boolean deleted = localFile.delete();
            if (deleted) {
                System.out.println("文件已删除：" + localFile);
            } else {
                System.out.println("无法删除文件：" + localFile);
            }
            File fParentlocaltion = localFile.getParentFile();
            if (!fParentlocaltion.exists()) { //判断文件父目录是否存在
                fParentlocaltion.mkdirs();
            }
            mFile.transferTo(localFile);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return fileUrl;
    }

    @Override
    public String importDataByExcel(String sFilePath) {
//        try {
//            File file = new File(sFilePath);
//            String outPath = file.getParent();
//            String unFilePath = multipleFileUnZip.fileUnZip(sFilePath, outPath);
//            File fileDir = new File(unFilePath);
//            if (fileDir.isDirectory()) {
//                String[] list = fileDir.list();
//                for (int i = 0; i < list.length; i++) {
//                    File f = new File(unFilePath + "\\" + list[i]);
//                    if (f.isFile()) {
//                        if (f.getName().toLowerCase().endsWith(".mdb")) {
//
//                        } else if (f.getName().toLowerCase().endsWith(".xlsx")) {
//                            List<WpCjTbxxbxj2023DTO> tbxxbxj2023DTOList = getDataByExcel(f.getPath());
//                            boolean b = InsertBatch(tbxxbxj2023DTOList);
//                        }
//                    }
//                }
//            } else if (fileDir.isFile()) {
//                if (fileDir.getName().toLowerCase().endsWith(".mdb")) {
//
//                } else if (fileDir.getName().toLowerCase().endsWith(".xlsx")) {
//                    List<WpCjTbxxbxj2023DTO> tbxxbxj2023DTOList = getDataByExcel(fileDir.getPath());
//                    boolean b = InsertBatch(tbxxbxj2023DTOList);
//                }
//            }
//            return "";
//        } catch (Exception ex) {
//            return ex.getMessage();
//        }
        return "";
    }

    @Override
    public List<Map> getshibyPch(Map<String, Object> parm) {
        return provAuditingMapper.getshibyPch(parm);
    }

    private List<WpCjTbxxbxj2023DTO> getDataByExcel(String filePath) {
        try {
            FileInputStream in = new FileInputStream(filePath);
            Workbook wk = StreamingReader.builder()
                    .rowCacheSize(100)  //缓存到内存中的行数，默认是10
                    .bufferSize(4096)  //读取资源时，缓存到内存的字节大小，默认是1024
                    .open(in);  //打开资源，必须，可以是InputStream或者是File，注意：只能打开XLSX格式的文件
            Sheet sheet = wk.getSheetAt(0);
            List<WpCjTbxxbxj2023DTO> tbxxbxjList = new ArrayList<>();
            int nStartRow = 3;
            int nRow = 0;
            //遍历所有的行
            for (Row row : sheet) {
                if (nRow++ < nStartRow)
                    continue;
//                WpCjTbxxbxj2023DTO tbxxb = new WpCjTbxxbxj2023DTO();
//                tbxxb.setId(row.getCell(0)==null?nRow:Integer.parseInt((row.getCell(0).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(0).getStringCellValue()));
//                tbxxb.setNf(row.getCell(1)==null?"":row.getCell(1).getStringCellValue()+"");
//                tbxxb.setTbxfsj(row.getCell(2)==null?"":row.getCell(2).getStringCellValue()+"");
//                tbxxb.setPcxx(row.getCell(3)==null?"":row.getCell(3).getStringCellValue()+"");
//                tbxxb.setSmc(row.getCell(4)==null?"":row.getCell(4).getStringCellValue()+"");
//                tbxxb.setSmc1(row.getCell(5)==null?"":row.getCell(5).getStringCellValue()+"");
//                tbxxb.setQxmc(row.getCell(6)==null?"":row.getCell(6).getStringCellValue()+"");
//                tbxxb.setXzqdm(row.getCell(7)==null?"":row.getCell(7).getStringCellValue()+"");
//                tbxxb.setJcbh(row.getCell(8)==null?"":row.getCell(8).getStringCellValue()+"");
//                tbxxb.setTblx(row.getCell(9)==null?"":row.getCell(9).getStringCellValue()+"");
//                tbxxb.setQsx(row.getCell(10)==null?"":row.getCell(10).getStringCellValue()+"");
//                tbxxb.setHsx(row.getCell(11)==null?"":row.getCell(11).getStringCellValue()+"");
//                tbxxb.setDqjh(row.getCell(12)==null?"":row.getCell(12).getStringCellValue()+"");
//                tbxxb.setTbzxdjd(row.getCell(13)==null?"":row.getCell(13).getStringCellValue()+"");
//                tbxxb.setTbzxdwd(row.getCell(14)==null?"":row.getCell(14).getStringCellValue()+"");
//                tbxxb.setJcmj(row.getCell(15)==null?0:Double.parseDouble((row.getCell(15).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(15).getStringCellValue()));
//                tbxxb.setSfcxbhtb(row.getCell(16)==null?"":row.getCell(16).getStringCellValue()+"");
//                tbxxb.setWqtbbh(row.getCell(17)==null?"":row.getCell(17).getStringCellValue()+"");
//                tbxxb.setBz(row.getCell(18)==null?"":row.getCell(18).getStringCellValue()+"");
//                tbxxb.setJctbxzgdmj(row.getCell(19)==null?0:Double.parseDouble((row.getCell(19).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(19).getStringCellValue()));
//                tbxxb.setJctbxznydzmj(row.getCell(20)==null?0:Double.parseDouble((row.getCell(20).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(20).getStringCellValue()));
//                tbxxb.setDlrdjsydmj(row.getCell(21)==null?0:Double.parseDouble((row.getCell(21).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(21).getStringCellValue()));
//                tbxxb.setDlrdwlydmj(row.getCell(22)==null?0:Double.parseDouble((row.getCell(22).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(22).getStringCellValue()));
//                tbxxb.setZjbntmj(row.getCell(23)==null?0:Double.parseDouble((row.getCell(23).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(23).getStringCellValue()));
//                tbxxb.setMjzbzddsdxjxzqdm(row.getCell(24)==null?"":row.getCell(24).getStringCellValue()+"");
//                tbxxb.setMjzbzddsdxjxzqmc(row.getCell(25)==null?"":row.getCell(25).getStringCellValue()+"");
//                tbxxb.setMjzbzddxzjxzqdm(row.getCell(26)==null?"":row.getCell(26).getStringCellValue()+"");
//                tbxxb.setMjzbzddxzjxzqmc(row.getCell(27)==null?"":row.getCell(27).getStringCellValue()+"");
//                tbxxb.setMjzbzddcjxzqdm(row.getCell(28)==null?"":row.getCell(28).getStringCellValue()+"");
//                tbxxb.setMjzbzddcjxzqmc(row.getCell(29)==null?"":row.getCell(29).getStringCellValue()+"");
//                tbxxb.setNzyjsydxmtbzj(row.getCell(30)==null?"":row.getCell(30).getStringCellValue()+"");
//                tbxxb.setTdzzysxm(row.getCell(31)==null?"":row.getCell(31).getStringCellValue()+"");
//                tbxxb.setZjggxmcjq(row.getCell(32)==null?"":row.getCell(32).getStringCellValue()+"");
//                tbxxb.setZjggxmjxq(row.getCell(33)==null?"":row.getCell(33).getStringCellValue()+"");
//                tbxxb.setGkfqdfkxm(row.getCell(34)==null?"":row.getCell(34).getStringCellValue()+"");
//                tbxxb.setWlydkfxm(row.getCell(35)==null?"":row.getCell(35).getStringCellValue()+"");
//                tbxxb.setGdxx(row.getCell(36)==null?"":row.getCell(36).getStringCellValue()+"");
//                tbxxb.setYsxmxx(row.getCell(37)==null?"":row.getCell(37).getStringCellValue()+"");
//                tbxxb.setSsnydxx(row.getCell(38)==null?"":row.getCell(38).getStringCellValue()+"");
//                tbxxb.setXxydxx(row.getCell(39)==null?"":row.getCell(39).getStringCellValue()+"");
//                tbxxb.setKqxx(row.getCell(40)==null?"":row.getCell(40).getStringCellValue()+"");
//                tbxxb.setQtkqxx(row.getCell(41)==null?"":row.getCell(41).getStringCellValue()+"");
//                tbxxb.setSklx(row.getCell(42)==null?"":row.getCell(42).getStringCellValue()+"");
//                tbxxb.setTskqmj(row.getCell(43)==null?"":row.getCell(43).getStringCellValue()+"");
//                tbxxb.setYjmj(row.getCell(44)==null?"":row.getCell(44).getStringCellValue()+"");
//                tbxxb.setZrbhqxx(row.getCell(45)==null?"":row.getCell(45).getStringCellValue()+"");
//                tbxxb.setYsxwpdlrdgdmj(row.getCell(46)==null?0:Double.parseDouble((row.getCell(46).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(46).getStringCellValue()));
//                tbxxb.setYsxwpdlrdnydmj(row.getCell(47)==null?0:Double.parseDouble((row.getCell(47).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(47).getStringCellValue()));
//                tbxxb.setYsxwpdlrdjsydmj(row.getCell(48)==null?0:Double.parseDouble((row.getCell(48).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(48).getStringCellValue()));
//                tbxxb.setYsxwpdlrdwlydmj(row.getCell(49)==null?0:Double.parseDouble((row.getCell(49).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(49).getStringCellValue()));
//                tbxxb.setYsxwpdlrdjbntmj(row.getCell(50)==null?0:Double.parseDouble((row.getCell(50).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(50).getStringCellValue()));
//                tbxxb.setWsxwpdlrdgdmj(row.getCell(51)==null?0:Double.parseDouble((row.getCell(51).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(51).getStringCellValue()));
//                tbxxb.setWsxwpdlrdnydmj(row.getCell(52)==null?0:Double.parseDouble((row.getCell(52).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(52).getStringCellValue()));
//                tbxxb.setWsxwpdlrdjsydmj(row.getCell(53)==null?0:Double.parseDouble((row.getCell(53).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(53).getStringCellValue()));
//                tbxxb.setWsxwpdlrdwlydmj(row.getCell(54)==null?0:Double.parseDouble((row.getCell(54).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(54).getStringCellValue()));
//                tbxxb.setWsxwpdlrdstmj(row.getCell(55)==null?0:Double.parseDouble((row.getCell(55).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(55).getStringCellValue()));
//                tbxxb.setWsxwpdlrdjbntmj(row.getCell(56)==null?0:Double.parseDouble((row.getCell(56).getStringCellValue() + "").equals("") ? 0 + "" : row.getCell(56).getStringCellValue()));
//                tbxxb.setSffgdk(row.getCell(57)==null?"":row.getCell(57).getStringCellValue()+"");
//                tbxxb.setSkbj(row.getCell(58)==null?"":row.getCell(58).getStringCellValue()+"");
//                tbxxb.setTbfl(row.getCell(59)==null?"":row.getCell(59).getStringCellValue()+"");
//                tbxxb.setXgsj(row.getCell(60)==null?"":row.getCell(60).getStringCellValue()+"");
//                tbxxb.setStbhhxmj(row.getCell(61)==null?"":row.getCell(61).getStringCellValue()+"");
//                tbxxb.setTbbsm(row.getCell(62)==null?"":row.getCell(62).getStringCellValue()+"");
//                tbxxb.setPch(row.getCell(63)==null?"":row.getCell(63).getStringCellValue()+"");
//                tbxxb.setNd(row.getCell(64)==null?"":row.getCell(64).getStringCellValue()+"");
//                tbxxb.setOpTime(row.getCell(65)==null?"":row.getCell(65).getStringCellValue()+"");
//                tbxxb.setReceivingCode(row.getCell(66)==null?"":row.getCell(66).getStringCellValue()+"");

//                tbxxb.setGjxfhzztq("自主提取");
//                tbxxbxjList.add(tbxxb);
            }
            return tbxxbxjList;
        } catch (Exception ex) {
            return null;
        }
    }

    private List<Map> getDataByMdb(String filePath) {
        List<Map> mapList = new ArrayList<>();
        return mapList;
    }

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    @Transactional
    public boolean InsertBatch(List<WpCjTbxxbxj2023DTO> tbxxbxj2023DTOList) {
        SqlSession sqlSession = null;
        try {
            //使用批处理
            sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
            WpCjTbxxbxj2023DTOMapper tbxxbMapper = sqlSession.getMapper(WpCjTbxxbxj2023DTOMapper.class);
            tbxxbxj2023DTOList.stream().forEach(tbxxbDao -> tbxxbMapper.insert(tbxxbDao));
            sqlSession.commit();
            return true;
        } catch (Exception ex) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            ex.printStackTrace();
            return false;
        } finally {
            // 确保SqlSession被关闭
            if (sqlSession != null) {
                sqlSession.close();
            }
        }
    }

    @Transactional
    public boolean InsertBatch1(List<WpCjDkxxbxj2023DTO> dkxxbxj2023DTOList) {
        SqlSession sqlSession = null;
        try {
            //使用批处理
            sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
            WpCjDkxxbxj2023DTOMapper dkxxbxjMapper = sqlSession.getMapper(WpCjDkxxbxj2023DTOMapper.class);
            dkxxbxj2023DTOList.stream().forEach(dkxxbDao -> dkxxbxjMapper.insert(dkxxbDao));
            sqlSession.commit();
            return true;
        } catch (Exception ex) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            ex.printStackTrace();
            return false;
        } finally {
            // 确保SqlSession被关闭
            if (sqlSession != null) {
                sqlSession.close();
            }
        }
    }

    @Override
    public WpCjTbhcjgshengj2023 getTbhcjgshengjByDkbh(Map<String, Object> parm) {
        WpCjTbhcjgshengj2023 tbhcjgshengjByDkbh = provAuditingMapper.getTbhcjgshengjByDkbh(parm);
        if (tbhcjgshengjByDkbh != null) {
//            List<WpCjTbhcjgSjHftgzmwj2023> xjHftgzmwj2023List = wpCjTbhcjgSjMapper.getTbhcjgSjHftgzmwjInfo(parm);
//            tbhcjgshengjByDkbh.setSjHftgzmwj2023List(xjHftgzmwj2023List);
//            List<WpCjTbhcjgSjQtpzwh2023> xjQtpzwh2023List = wpCjTbhcjgSjMapper.getTbhcjgSjQtpzwhInfo(parm);
//            tbhcjgshengjByDkbh.setSjQtpzwh2023List(xjQtpzwh2023List);
//            List<WpCjTbhcjgSjQtsftgxxydss2023> xjQtsftgxxydss2023List = wpCjTbhcjgSjMapper.getTbhcjgSjQtsftgxxydssInfo(parm);
//            tbhcjgshengjByDkbh.setSjQtsftgxxydss2023List(xjQtsftgxxydss2023List);
//            List<WpCjTbhcjgSjQtsfzygd2023> xjQtsfzygd2023List = wpCjTbhcjgSjMapper.getTbhcjgSjQtsfzygdInfo(parm);
//            tbhcjgshengjByDkbh.setSjQtsfzygd2023List(xjQtsfzygd2023List);
//            List<WpCjTbhcjgSjWfpzwh2023> xjWfpzwh2023List = wpCjTbhcjgSjMapper.getTbhcjgSjWfpzwhInfo(parm);
//            tbhcjgshengjByDkbh.setSjWfpzwh2023List(xjWfpzwh2023List);
//            List<WpCjTbhcjgSjWftgzmwj2023> xjWftgzmwj2023List = wpCjTbhcjgSjMapper.getTbhcjgSjWftgzmwjInfo(parm);
//            tbhcjgshengjByDkbh.setSjWftgzmwj2023List(xjWftgzmwj2023List);
        }
        return tbhcjgshengjByDkbh;
    }

    @Override
    public Integer saveShengTbjg(Map<String, Object> parm) {
        Integer rest = 0;
        Map<String, Object> item = commonSjMapper.queryHcJgById(parm);
        //全部删除
        if (item != null) {
            commonSjMapper.deleteHcJg(parm);
            commonSjMapper.deleteHcjg_hf_dtPwwj(parm);
            commonSjMapper.deleteHcjg_wf_wfpzwh(parm);
            commonSjMapper.deleteHcjg_wf_wftgzmwj(parm);
            commonSjMapper.deleteHcjg_qt_qtpzwh(parm);
            commonSjMapper.deleteHcjg_qt_qtsftgxxydss(parm);
            commonSjMapper.deleteHcjg_qt_qtsfzygd(parm);
        }
        parm.put("sfhc", "是");
        parm.put("submit_date", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
        rest = commonSjMapper.addHcjg(parm);  //存储结果
        String strPdlx = parm.get("pdlx") + "";

        String domains = parm.get("domains") + "";
        if (!domains.equals("[]") && !domains.equals("null") && domains != "null") {
            JSONArray arraylist = JSONObject.parseArray(domains);

            for (int i = 0; i < arraylist.size(); i++) { //遍历输出
                JSONObject jsonObject = arraylist.getJSONObject(i);
                String domainType = jsonObject.getString("domainType");
                if (strPdlx.equals("符合法律法规和相关政策用地")) {
                    ModelMap map = new ModelMap();
                    map.put("tbbh", parm.get("tbbh"));
                    map.put("xzqdm", parm.get("xzqdm"));
                    map.put("pch", parm.get("pch"));
                    map.put("sort", jsonObject.getString("key"));
                    map.put("hf_zlpwlx1", jsonObject.getString("hfZlpwlx1"));
                    map.put("hf_pzwh", jsonObject.getString("hfPzwh"));
                    map.put("hf_pzxmmc", jsonObject.getString("hfPzxmmc"));
                    map.put("hf_pzzygdmj", jsonObject.getString("hfPzzygdmj"));
                    map.put("hf_pzzygdmjdw", jsonObject.getString("hfPzzygdmjdw"));
                    map.put("hf_pzsj", jsonObject.getString("hfPzsj"));
                    map.put("hf_zlpwlx2", jsonObject.getString("hfZlpwlx2"));
                    map.put("hf_zlpwclmc", jsonObject.getString("hfZlpwclmc"));
                    map.put("ywhj", parm.get("ywhj"));
                    map.put("status", "");
                    int hf_rest = commonSjMapper.addHcjg_hf_DtPwwj(map);
                } else if (strPdlx.equals("不符合法律法规和相关政策用地")) {
                    if (jsonObject.getString("wfZlpwlx1") != null || jsonObject.getString("wfZlpwlx2") != null) {
                        ModelMap map = new ModelMap();
                        map.put("tbbh", parm.get("tbbh"));
                        map.put("xzqdm", parm.get("xzqdm"));
                        map.put("pch", parm.get("pch"));
                        map.put("sort", jsonObject.getString("key"));
                        map.put("wf_zlpwlx1", jsonObject.getString("wfZlpwlx1"));
                        map.put("wf_pzwh", jsonObject.getString("wfPzwh"));
                        map.put("wf_pzxmmc", jsonObject.getString("wfPzxmmc"));
                        map.put("wf_pzzygdmj", jsonObject.getString("wfPzzygdmj"));
                        map.put("wf_pzzygdmjdw", jsonObject.getString("wfPzzygdmjdw"));
                        map.put("wf_pzsj", jsonObject.getString("wfPzsj"));

                        map.put("wf_zlpwlx2", jsonObject.getString("wfZlpwlx2"));
                        map.put("wf_zlpwclmc", jsonObject.getString("wfZlpwclmc"));
                        map.put("ywhj", parm.get("ywhj"));
                        map.put("status", "");
                        commonSjMapper.addHcjg_wf_wftgzmwj(map);
                    } else {
                        ModelMap map = new ModelMap();
                        map.put("tbbh", parm.get("tbbh"));
                        map.put("xzqdm", parm.get("xzqdm"));
                        map.put("pch", parm.get("pch"));
                        map.put("sort", jsonObject.getString("key"));
                        map.put("wf_pzwh", jsonObject.getString("wfPzwh"));
                        map.put("wf_pzxmmc", jsonObject.getString("wfPzxmmc"));
                        map.put("wf_pzsj", jsonObject.getString("wfPzsj"));
                        map.put("ywhj", parm.get("ywhj"));
                        map.put("status", "");
                        commonSjMapper.addHcjg_wf_wfpzwh(map);
                    }
                } else if (strPdlx.equals("其他用地")) {
                    if (jsonObject.getString("qtPzwh") != null) {
                        ModelMap qtpzwh_map = new ModelMap();
                        qtpzwh_map.put("tbbh", parm.get("tbbh"));
                        qtpzwh_map.put("xzqdm", parm.get("xzqdm"));
                        qtpzwh_map.put("pch", parm.get("pch"));
                        qtpzwh_map.put("sort", jsonObject.getString("key"));
                        qtpzwh_map.put("qt_pzwh", jsonObject.getString("qtPzwh"));
                        qtpzwh_map.put("qt_pzxmmc", jsonObject.getString("qtPzxmmc"));
                        qtpzwh_map.put("qt_pzsj", jsonObject.getString("qtPzsj"));
                        qtpzwh_map.put("ywhj", parm.get("ywhj"));
                        qtpzwh_map.put("status", "");
                        rest = commonSjMapper.adddHcjg_qt_qtpzwh(qtpzwh_map);
                    } else if (jsonObject.getString("qtTgbawjsj") != null) {
                        ModelMap qtsfzygd_map = new ModelMap();
                        qtsfzygd_map.put("tbbh", parm.get("tbbh"));
                        qtsfzygd_map.put("xzqdm", parm.get("xzqdm"));
                        qtsfzygd_map.put("pch", parm.get("pch"));
                        qtsfzygd_map.put("sort", jsonObject.getString("key"));
                        qtsfzygd_map.put("qt_tgbawjsj", jsonObject.getString("qtTgbawjsj"));
                        qtsfzygd_map.put("qt_clmc", jsonObject.getString("qtClmc"));
                        qtsfzygd_map.put("ywhj", parm.get("ywhj"));
                        qtsfzygd_map.put("status", "");
                        rest = commonSjMapper.addHcjg_qt_qtsfzygd(qtsfzygd_map);
                    } else if (jsonObject.getString("qtSftgxxydssclmc") != null) {
                        ModelMap qtsftgxxydss_map = new ModelMap();
                        qtsftgxxydss_map.put("tbbh", parm.get("tbbh"));
                        qtsftgxxydss_map.put("xzqdm", parm.get("xzqdm"));
                        qtsftgxxydss_map.put("pch", parm.get("pch"));
                        qtsftgxxydss_map.put("sort", jsonObject.getString("key"));

                        qtsftgxxydss_map.put("qt_sftgxxydssclmc", jsonObject.getString("qtSftgxxydssclmc"));
                        qtsftgxxydss_map.put("qt_sftgxxydsspfsj", jsonObject.getString("qtSftgxxydsspfsj"));
                        qtsftgxxydss_map.put("ywhj", parm.get("ywhj"));
                        qtsftgxxydss_map.put("status", "");
                        rest = commonSjMapper.addHcjg_qt_qtsftgxxydss(qtsftgxxydss_map);
                    }
                }
            }
        }


//        //rest = provAuditingMapper.saveShengTbjg(parm);
//        if ("符合法律法规和相关政策用地".equals(parm.get("pdlx"))) {
//            rest = provAuditingMapper.saveShengTbjgHF(parm);
//            List<WpCjTbhcjgSjHftgzmwj2023> wpCjTbhcjgSjHftgzmwj2023List = (List<WpCjTbhcjgSjHftgzmwj2023>) parm.get("sjHftgzmwj2023List");
//            if (wpCjTbhcjgSjHftgzmwj2023List != null && wpCjTbhcjgSjHftgzmwj2023List.size() > 0) {
//                for (WpCjTbhcjgSjHftgzmwj2023 wpCjTbhcjgSjHftgzmwj2023 : wpCjTbhcjgSjHftgzmwj2023List) {
//                    provAuditingMapper.saveSjTbchjgHftgzmwj(wpCjTbhcjgSjHftgzmwj2023);
//                }
//            }
//        } else if ("不符合法律法规和相关政策用地".equals(parm.get("pdlx"))) {
//            rest = provAuditingMapper.saveShengTbjgWF(parm);
//            List<WpCjTbhcjgSjWfpzwh2023> wpCjTbhcjgSjWfpzwh2023s = (List<WpCjTbhcjgSjWfpzwh2023>) parm.get("sjWfpzwh2023List");
//            if (wpCjTbhcjgSjWfpzwh2023s != null && wpCjTbhcjgSjWfpzwh2023s.size() > 0) {
//                for (WpCjTbhcjgSjWfpzwh2023 wpCjTbhcjgSjWfpzwh2023 : wpCjTbhcjgSjWfpzwh2023s) {
//                    provAuditingMapper.saveSjTbchjgWfpzwh(wpCjTbhcjgSjWfpzwh2023);
//                }
//            }
//            List<WpCjTbhcjgSjWftgzmwj2023> wpCjTbhcjgSjWftgzmwj2023List = (List<WpCjTbhcjgSjWftgzmwj2023>) parm.get("sjWftgzmwj2023List");
//            if (wpCjTbhcjgSjWftgzmwj2023List != null && wpCjTbhcjgSjWftgzmwj2023List.size() > 0) {
//                for (WpCjTbhcjgSjWftgzmwj2023 wpCjTbhcjgSjWftgzmwj2023 : wpCjTbhcjgSjWftgzmwj2023List) {
//                    provAuditingMapper.saveSjTbchjgWftgzmwj(wpCjTbhcjgSjWftgzmwj2023);
//                }
//            }
//        } else if ("其他用地".equals(parm.get("pdlx"))) {
//            rest = provAuditingMapper.saveShengTbjgQT(parm);
//            List<WpCjTbhcjgSjQtpzwh2023> wpCjTbhcjgSjQtpzwh2023s = (List<WpCjTbhcjgSjQtpzwh2023>) parm.get("domains");
//            if (wpCjTbhcjgSjQtpzwh2023s != null && wpCjTbhcjgSjQtpzwh2023s.size() > 0) {
//                for (WpCjTbhcjgSjQtpzwh2023 wpCjTbhcjgSjQtpzwh2023 : wpCjTbhcjgSjQtpzwh2023s) {
//                    provAuditingMapper.saveSjTbchjgQtpzwh(wpCjTbhcjgSjQtpzwh2023);
//                }
//            }
//            List<WpCjTbhcjgSjQtsftgxxydss2023> wpCjTbhcjgSjQtsftgxxydss2023List = (List<WpCjTbhcjgSjQtsftgxxydss2023>) parm.get("sjQtsftgxxydss2023List");
//            if (wpCjTbhcjgSjQtsftgxxydss2023List != null && wpCjTbhcjgSjQtsftgxxydss2023List.size() > 0) {
//                for (WpCjTbhcjgSjQtsftgxxydss2023 wpCjTbhcjgSjQtsftgxxydss2023 : wpCjTbhcjgSjQtsftgxxydss2023List) {
//                    provAuditingMapper.saveSjTbchjgQtsftgxxydss(wpCjTbhcjgSjQtsftgxxydss2023);
//                }
//            }
//        }
//        List<WpCjTbhcjgSjQtsfzygd2023> wpCjTbhcjgSjQtsfzygd2023s = (List<WpCjTbhcjgSjQtsfzygd2023>) parm.get("sjQtsfzygd2023List");
//        if (wpCjTbhcjgSjQtsfzygd2023s != null && wpCjTbhcjgSjQtsfzygd2023s.size() > 0) {
//            for (WpCjTbhcjgSjQtsfzygd2023 wpCjTbhcjgSjQtsfzygd2023 : wpCjTbhcjgSjQtsfzygd2023s) {
//                provAuditingMapper.saveSjTbchjgQtsfzygd(wpCjTbhcjgSjQtsfzygd2023);
//            }
//        }
        Map<String, Object> tbhcjgsm = commonSjService.getHcjgsmBytbbh(parm);
        parm.put("hcjgsm", tbhcjgsm.get("hcjgsm").toString());
        int k = provAuditingMapper.updatehcjgsmByxzqdm(parm);

        return rest;
    }

    @Autowired
    CommonSjService commonSjService;

    @Override
    public Integer shengSubmit(Map<String, Object> parm) {
        Integer rest = 0;
        rest = saveShengTbjg(parm);

        Map<String, Object> tbhcjgsm = commonSjService.getHcjgsmBytbbh(parm);
        parm.put("hcjgsm", tbhcjgsm.get("hcjgsm").toString());
        parm.put("dkzt", "8");
        parm.put("dkbh", parm.get("tbbh") + "");
        xjtbTbBaseMapper.updateDkxxbDkzt(parm);
        parm.put("czsj", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
        parm.put("result", parm.get("hcjl"));
        parm.put("sm", parm.get("hcsm"));
        parm.put("userlevel", "省");
        xjtbTbBaseMapper.saveDkxxbxjlz(parm);
        return rest;
    }


    @Override
    public Integer shengThxggty(Map<String, Object> param) {
        //先退回到国土云
        Integer rest = 0;
        try {
            String postURL = "";
            String data = "";
            {
                postURL = "https://jg.landcloud.org.cn:8553/webapi/token";
                data = "client_id=web&client_secret=e46232c20609435eba54b7576de935dd&grant_type=password&username=gtdcy1083849&password=eaaf6dd6266f1b326bec05c996926983";
            }
            URL url = new URL(postURL);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");

            conn.setDoOutput(true);
            conn.setDoInput(true);
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8");

            out.write(data);
            //缓冲数据
            out.flush();
            //获取URLConnection对象对应的输入流
            InputStream is = conn.getInputStream();
            int count = 0;
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[4096];
            while ((count = is.read(buffer)) != -1) {
                byteArrayOutputStream.write(buffer, 0, count);
            }
            byte[] datas = byteArrayOutputStream.toByteArray();
            byteArrayOutputStream.close();
            //关闭流
            is.close();
            conn.disconnect();
            String result = new String(datas, 0, datas.length, "utf-8");
            String str = thxggty(result, param); //区县所有地块信息

            if (str.equals("")) {
                param.put("czsj", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
                param.put("result", param.get("hcjl"));
                param.put("sm", param.get("hcsm") + "退回至国土云");
                //param.put("userlevel", "市");
                param.put("userlevel", "省");
                xjtbTbBaseMapper.saveDkxxbxjlz(param);

                param.put("dkzt", "7");
                param.put("thsj", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
                rest = dkShCityMapper.updateDkzt(param);
            }
        } catch (Exception ex) {
            rest = 0;
        }
        return rest;
    }

    @Override
    public List<Map> getProvExtractionrecord(Map<String, Object> parm) {
        return provAuditingMapper.getProvExtractionrecord(parm);
    }

    @Override
    public Integer getProvExtractionrecordCount(Map<String, Object> parm) {
        return provAuditingMapper.getProvExtractionrecordCount(parm);
    }

    @Override
    public List<Map> getProvExtractionrecordYear(Map<String, Object> parm) {
        return provAuditingMapper.getProvExtractionrecordYear(parm);
    }

    @Override
    public List<Map> getProvExtractionrecordPc(Map<String, Object> parm) {
        return provAuditingMapper.getProvExtractionrecordPc(parm);
    }

    @Override
    public List<Map> getProvExtractionDatasmc1(Map<String, Object> parm) {
        return provAuditingMapper.getProvExtractionDatasmc1(parm);
    }

    @Override
    public List<Map> getProvExtractionDataqxmc(Map<String, Object> parm) {
        return provAuditingMapper.getProvExtractionDataqxmc(parm);
    }

    @Override
    public List<String> getWyname(Map<String, Object> parm) {
        return provAuditingMapper.getWyname(parm);
    }

    private String thxggty(String str, Map<String, Object> param) {
        String rest = "";
        try {
            String postURL = "";
            String token = "";
            String token_type = "";
            Map mapType = JSON.parseObject(str, Map.class);
            {
                for (Object obj : mapType.keySet()) {

                    if ((obj + "").equals("access_token")) {
                        token = mapType.get("access_token") + "";
                        token_type = mapType.get("token_type") + "";
                    }
                }
                System.out.println(token);
                //接口地址
                postURL = "https://jg.landcloud.org.cn:8553/webapi/open/wpzf/hcfkth";
            }
            URL url = new URL(postURL);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("Charset", "utf-8");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
            conn.setRequestProperty("Content-Type", "application/json;charset=utf-8 ");
            conn.setRequestProperty("Authorization", token_type + " " + token);
            //  conn.setRequestProperty("token", token);
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setConnectTimeout(2000);
            conn.setReadTimeout(2000);
            //获取URLConnection对象对应的输出流
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8");
            //  out = new PrintWriter(conn.getOutputStream());
            //发送请求参数即数据
            //String xmbh="210115S120240216LJ00005";
            String ywlx = "wpzfdk24";
            String content = param.get("thyy").toString();
            String tbbh = param.get("tbbh").toString();
            Boolean thxj = true;
            String data = "{\"ywlx\":\"" + ywlx + "\",\"content\":\"" + content + "\",\"thxj\":" + thxj + ",\"tbbhs\":[\"" + tbbh + "\"]}";
            System.out.println("---------退回地块列表参数------" + data);
            out.write(data);
            out.flush();
            InputStream is = conn.getInputStream();
            int count = 0;
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[4096];
            while ((count = is.read(buffer)) != -1) {
                byteArrayOutputStream.write(buffer, 0, count);
            }
            byte[] datas = byteArrayOutputStream.toByteArray();

            byteArrayOutputStream.close();
            is.close();
            conn.disconnect();
            rest = new String(datas, 0, datas.length, "utf-8");
            JSONObject obj = JSONObject.parseObject(rest);
            String status = obj.get("status").toString();
            if (status.equals("0") && obj.get("code").toString().equals("200")) {
                return "";
            } else {
                return "国土云退回失败";
            }

        } catch (Exception ex) {
            return "国土云退回失败,失败原因" + ex.toString();
        }
    }

    @Override
    public Integer shengThxg(Map<String, Object> param) {
        Integer rest = 0;
        param.put("czsj", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
        param.put("result", param.get("hcjl"));
        param.put("sm", param.get("hcsm"));
        //param.put("userlevel", "市");
        param.put("userlevel", "省");
        xjtbTbBaseMapper.saveDkxxbxjlz(param);
        param.put("dkzt", "7");
        param.put("thsj", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
        rest = dkShCityMapper.updateDkzt(param);
        return rest;
    }

    @Override
    public List<Map<String, Object>> queryFjInfo(Map<String, Object> parms) {
        return provAuditingMapper.queryFjInfo(parms);
    }

    @Override
    public Integer saveThyy(Map<String, Object> parms) {
        return provAuditingMapper.saveThyy(parms);
    }

    @Override
    public String getGtyData(Map<String, Object> parms) {
        String rest = "";
        try {
            String tbbh = parms.get("tbbh") + "";
            String content = parms.get("content") + "";
            String type = parms.get("type") + "";

            String postURL = "";
            String data = "";
            {
                postURL = "https://jg.landcloud.org.cn:8553/webapi/token";
                data = "client_id=web&client_secret=e46232c20609435eba54b7576de935dd&grant_type=password&username=a53e0c14ee900728f36bba014d975982&password=b30c775c48e9ba92ade95e427a5242b0";
            }
            URL url = new URL(postURL);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");

            conn.setDoOutput(true);
            conn.setDoInput(true);
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8");

            out.write(data);
            //缓冲数据
            out.flush();
            //获取URLConnection对象对应的输入流
            InputStream is = conn.getInputStream();
            int count = 0;
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] buffer = new byte[4096];
            while ((count = is.read(buffer)) != -1) {
                byteArrayOutputStream.write(buffer, 0, count);
            }
            byte[] datas = byteArrayOutputStream.toByteArray();

            byteArrayOutputStream.close();
            //关闭流
            is.close();

            conn.disconnect();
            String result = new String(datas, 0, datas.length, "utf-8");
            if ("th".equals(type)) {
                rest = gtyTh(result, tbbh, content);
            } else if ("tj".equals(type)) {
                rest = gtyTj(result, tbbh, content);
            }
        } catch (MalformedURLException ex) {
            throw new RuntimeException(ex);
        } catch (UnsupportedEncodingException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        return rest;
    }

    @Override
    public Integer saveLz(Map<String, Object> parm) {
        parm.put("czsj", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
        parm.put("result", parm.get("hcjl"));
        parm.put("sm", parm.get("hcsm"));
        parm.put("userlevel", "省");
        parm.put("dkbh", parm.get("tbbh"));
        return xjtbTbBaseMapper.saveDkxxbxjlz(parm);
    }

    public String gtyTh(String str, String tbbh, String content) {
        String rest = "";
        try {
            String postURL = "";
            String token = "";
            String token_type = "";
            Map mapType = JSON.parseObject(str, Map.class);
            {
                for (Object obj : mapType.keySet()) {
                    if ((obj + "").equals("access_token")) {
                        token = mapType.get("access_token") + "";
                        token_type = mapType.get("token_type") + "";
                    }
                }
                System.out.println(token);
                //接口地址
                postURL = "https://dc2.landcloud.org.cn:9443/webapi/open/wpzf/hcfkth";
            }


            URL url = new URL(postURL);
            //打开和url之间的连接
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            //请求方式
            conn.setRequestMethod("POST");
            //设置通用的请求属性
            String encoding = Base64.encode(str.getBytes());
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("Charset", "utf-8");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
            conn.setRequestProperty("Content-Type", "application/json;charset=utf-8 ");
            conn.setRequestProperty("Authorization", token_type + " " + token);
            //  conn.setRequestProperty("token", token);
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setConnectTimeout(10000);
            conn.setReadTimeout(10000);
            //获取URLConnection对象对应的输出流
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8");
            //  out = new PrintWriter(conn.getOutputStream());
            //发送请求参数即数据

            if (StringUtils.isNotBlank(tbbh)) {
                String data = "{\n" +
                        "    \"ywlx\": \"wpzfdktb23\",\n" +
                        "    \"content\": \"" + content + "\",\n" +
                        "    \"thxj\": true,\n" +
                        "    \"tbbhs\": [\n" +
                        "        \"" + tbbh + "\"\n" +
                        "    ]\n" +
                        "}";
                System.out.println("---------3232------" + data);
                out.write(data);
                //缓冲数据
                out.flush();
                //获取URLConnection对象对应的输入流
                InputStream is = conn.getInputStream();

                int count = 0;

                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

                byte[] buffer = new byte[4096];

                while ((count = is.read(buffer)) != -1) {

                    byteArrayOutputStream.write(buffer, 0, count);
                }
                byte[] datas = byteArrayOutputStream.toByteArray();

                byteArrayOutputStream.close();
                is.close();
                conn.disconnect();
                rest = new String(datas, 0, datas.length, "utf-8");
                System.out.println(rest);
                //writeLog(UtilTool.GetTime_1()+"：结束请求举证照片接口\n");
            }

        } catch (Exception e) {
            rest = "网络异常，请稍后重试！";
            //writeLog(UtilTool.GetTime_1()+"："+e.getMessage()+"\n");
            throw new RuntimeException(e.getMessage());
        }
        return rest;
    }

    public String gtyTj(String str, String tbbh, String content) {
        String rest = "";
        try {
            String postURL = "";
            String token = "";
            String token_type = "";
            Map mapType = JSON.parseObject(str, Map.class);
            {
                for (Object obj : mapType.keySet()) {
                    if ((obj + "").equals("access_token")) {
                        token = mapType.get("access_token") + "";
                        token_type = mapType.get("token_type") + "";
                    }
                }
                System.out.println(token);
                //接口地址
                postURL = "https://dc2.landcloud.org.cn:9443/webapi/open/wpzf/hcfktj";
            }


            URL url = new URL(postURL);
            //打开和url之间的连接
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            //请求方式
            conn.setRequestMethod("POST");
            //设置通用的请求属性
            String encoding = Base64.encode(str.getBytes());
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("Charset", "utf-8");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
            conn.setRequestProperty("Content-Type", "application/json;charset=utf-8 ");
            conn.setRequestProperty("Authorization", token_type + " " + token);
            //  conn.setRequestProperty("token", token);
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setConnectTimeout(10000);
            conn.setReadTimeout(10000);
            //获取URLConnection对象对应的输出流
            OutputStreamWriter out = new OutputStreamWriter(conn.getOutputStream(), "utf-8");
            //  out = new PrintWriter(conn.getOutputStream());
            //发送请求参数即数据

            if (StringUtils.isNotBlank(tbbh)) {
                String data = "{\n" +
                        "    \"ywlx\": \"wpzfdktb23\",\n" +
                        "    \"level\": \"4\",\n" +
                        "    \"content\": \"" + content + "\",\n" +
                        "    \"thxj\": true,\n" +
                        "    \"tbbhs\": [\n" +
                        "        \"" + tbbh + "\"\n" +
                        "    ]\n" +
                        "}";
                System.out.println("---------3232------" + data);
                out.write(data);
                //缓冲数据
                out.flush();
                //获取URLConnection对象对应的输入流
                InputStream is = conn.getInputStream();

                int count = 0;

                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

                byte[] buffer = new byte[4096];

                while ((count = is.read(buffer)) != -1) {

                    byteArrayOutputStream.write(buffer, 0, count);
                }
                byte[] datas = byteArrayOutputStream.toByteArray();

                byteArrayOutputStream.close();
                is.close();
                conn.disconnect();
                rest = new String(datas, 0, datas.length, "utf-8");
                System.out.println(rest);
                //writeLog(UtilTool.GetTime_1()+"：结束请求举证照片接口\n");
            }

        } catch (Exception e) {
            rest = "网络异常，请稍后重试！";
            //writeLog(UtilTool.GetTime_1()+"："+e.getMessage()+"\n");
            throw new RuntimeException(e.getMessage());
        }
        return rest;
    }
}
